package com.whmskj.xjlhsc.service.impl;

import com.whmskj.xjlhbc.core.Page;
import com.whmskj.xjlhbc.db.DataSource;
import com.whmskj.xjlhbc.db.DataSourceType;
import com.whmskj.xjlhbc.db.DynamicDataSourceContextHolder;
import com.whmskj.xjlhsc.entity.ACRealTime;
import com.whmskj.xjlhsc.entity.Shachangacrealtime;
import com.whmskj.xjlhsc.entity.Shachangdbhouryield;
import com.whmskj.xjlhsc.mapper.AcRealtimeMapper;
import com.whmskj.xjlhsc.service.AcRealtimeService;
import com.whmskj.xjlhsc.utils.SCUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: Sakura
 * @Date: 2025/8/13 10:22
 * @Version: v1.0.0
 * @Description: TODO
 **/
@Service
public class AcRealtimeServiceImpl implements AcRealtimeService {
    @Autowired
    private AcRealtimeMapper acRealtimeMapper;

    @Override
    @DataSource(DataSourceType.SC)
    public List<Shachangdbhouryield> getLatestAcData(String process) {
        return acRealtimeMapper.findLatestAcData(process); // 返回 AcRealtime 列表
    }

    /**
     * 温湿度列表
     * @param keyWord
     * @return
     */
    @Override
    public Map<String,Object> acList(String keyWord) {
        DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.SC.name());
        List<ACRealTime> list =  acRealtimeMapper.selectAcList(keyWord);
        int normal=0; //正常
        int fault=0; //异常
        for (ACRealTime acrealtime : list) {
            if (acrealtime.getDeviceState().equals("正常运行")){
                normal++;
            }
            else {
                fault++;
            }
        }
        Map<String,Object> map=new HashMap<>();
        map.put("normal",normal);
        map.put("fault",fault);
        map.put("list",list);
        return map;
    }


}
